<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="110px"
    >
      <el-form-item label="抽取轮次" prop="extractBatchNum">
        <el-input
          v-model="queryParams.extractBatchNum"
          placeholder="请输入抽取轮次"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="抽取人数" prop="extractExpertNum">
        <el-input
          v-model="queryParams.extractExpertNum"
          placeholder="请输入抽取人数"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="抽取时间" prop="extractTime">
        <el-date-picker
          v-model="queryParams.extractTime"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
          class="!w-240px"
        />
      </el-form-item>
      
      <el-form-item label="专家姓名" prop="expertName">
        <el-input
          v-model="queryParams.expertName"
          placeholder="请输入专家姓名"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="专家单位" prop="expertUnit">
        <el-input
          v-model="queryParams.expertUnit"
          placeholder="请输入专家单位"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="专家电话" prop="expertPhone">
        <el-input
          v-model="queryParams.expertPhone"
          placeholder="请输入电话"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="所属专家库" prop="expertMajor">
        <el-input
          v-model="queryParams.expertMajor"
          placeholder="请选择专家库"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="专家职称" prop="expertTitle">
        <el-input
          v-model="queryParams.expertTitle"
          placeholder="请输入职称"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="身份代码" prop="expertIden">
        <el-input
          v-model="queryParams.expertIden"
          placeholder="请输入身份代码"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="项目单位" prop="projectUnit">
        <el-input
          v-model="queryParams.projectUnit"
          placeholder="请输入项目单位"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="联系人" prop="projectContacts">
        <el-input
          v-model="queryParams.projectContacts"
          placeholder="请输入联系人"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="联系人电话" prop="projectPhone">
        <el-input
          v-model="queryParams.projectPhone"
          placeholder="请输入联系人电话"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="项目所需专家库" prop="projectMajor">
        <el-input
          v-model="queryParams.projectMajor"
          placeholder="请输入项目所需专家库"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="项目时间" prop="projectTime">
        <el-date-picker
          v-model="queryParams.projectTime"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="项目地址" prop="projectAddress">
        <el-input
          v-model="queryParams.projectAddress"
          placeholder="请输入项目地址"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="项目金额" prop="projectAmount">
        <el-input
          v-model="queryParams.projectAmount"
          placeholder="请输入项目金额"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item label="项目招标时间" prop="projectTendersTime">
        <el-date-picker
          v-model="queryParams.projectTendersTime"
          value-format="YYYY-MM-DD HH:mm:ss"
          type="daterange"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
        <!-- <el-button
          type="primary"
          plain
          @click="openForm('create')"
          v-hasPermi="['expert:extract-info:create']"
        >
          <Icon icon="ep:plus" class="mr-5px" /> 新增
        </el-button> -->
        <el-button
          type="success"
          plain
          @click="handleExport"
          :loading="exportLoading"
          v-hasPermi="['expert:extract-info:export']"
        >
          <Icon icon="ep:download" class="mr-5px" /> 导出
        </el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="项目单位" align="center" prop="projectUnit" />
      <el-table-column label="联系人" align="center" prop="projectContacts" />
      <el-table-column label="联系人电话" align="center" prop="projectPhone" />
      <el-table-column label="项目所需专家库" align="center" prop="projectMajor" />
      <el-table-column label="项目时间" align="center" prop="projectTime" />
      <el-table-column label="项目地址" align="center" prop="projectAddress" />
      <el-table-column label="项目金额" align="center" prop="projectAmount" />
      <el-table-column
        label="项目招标时间"
        align="center"
        prop="projectTendersTime"
        :formatter="dateFormatter"
        width="180px"
      />
      <el-table-column label="抽取轮次" align="center" prop="extractBatchNum" />
      <el-table-column label="抽取人数" align="center" prop="extractExpertNum" />
      <el-table-column label="抽取专家库" align="center" prop="extractMajor" />
      <el-table-column
        label="抽取时间"
        align="center"
        prop="extractTime"
        :formatter="dateFormatter"
        width="180px"
      />
      <el-table-column label="专家姓名" align="center" prop="expertName" />
      <el-table-column label="专家单位" align="center" prop="expertUnit" />
      <el-table-column label="专家电话" align="center" prop="expertPhone" />
      <el-table-column label="专家所属专家库" align="center" prop="expertMajor" />
      <el-table-column label="专家职称" align="center" prop="expertTitle" />
      <el-table-column label="身份代码" align="center" prop="expertIden" />
      <el-table-column label="身份证号" align="center" prop="idNumber" />
      <el-table-column label="备注" align="center" prop="remark" />
      <!-- <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        :formatter="dateFormatter"
        width="180px"
      /> -->
      <el-table-column label="操作" align="center" min-width="120px">
        <template #default="scope">
          <!-- <el-button
            link
            type="primary"
            @click="openForm('update', scope.row.id)"
            v-hasPermi="['expert:extract-info:update']"
          >
            编辑
          </el-button> -->
          <el-button
            link
            type="danger"
            @click="handleDelete(scope.row.id)"
            v-hasPermi="['expert:extract-info:delete']"
          >
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>

  <!-- 表单弹窗：添加/修改 -->
  <ExtractInfoForm ref="formRef" @success="getList" />
</template>

<script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime'
import download from '@/utils/download'
import { ExtractInfoApi, ExtractInfoVO } from '@/api/expert/extractinfo'
import ExtractInfoForm from './ExtractInfoForm.vue'

/** 抽签结果 列表 */
defineOptions({ name: 'ExtractInfo' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const list = ref<ExtractInfoVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  id: undefined,
  extractBatchNum: undefined,
  extractExpertNum: undefined,
  extractTime: [],
  expertId: undefined,
  projectId: undefined,
  expertName: undefined,
  expertUnit: undefined,
  expertPhone: undefined,
  expertMajor: undefined,
  expertTitle: undefined,
  expertIden: undefined,
  projectName: undefined,
  projectUnit: undefined,
  projectContacts: undefined,
  projectPhone: undefined,
  projectMajor: undefined,
  projectTime: [],
  projectAddress: undefined,
  projectAmount: undefined,
  projectTendersTime: [],
  remark: undefined,
  extract_major: undefined,
  major: undefined,
  createTime: [],
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await ExtractInfoApi.getExtractInfoPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 添加/修改操作 */
const formRef = ref()
// const openForm = (type: string, id?: number) => {
//   formRef.value.open(type, id)
// }

/** 删除按钮操作 */
const handleDelete = async (id: number) => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    // 发起删除
    await ExtractInfoApi.deleteExtractInfo(id)
    message.success(t('common.delSuccess'))
    // 刷新列表
    await getList()
  } catch {}
}

/** 导出按钮操作 */
const handleExport = async () => {
  try {
    // 导出的二次确认
    await message.exportConfirm()
    // 发起导出
    exportLoading.value = true
    const data = await ExtractInfoApi.exportExtractInfo(queryParams)
    download.excel(data, '抽签结果.xls')
  } catch {
  } finally {
    exportLoading.value = false
  }
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>